﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using QuanLyPhongMach.Context;
using QuanLyPhongMach.Platform;
using QuanLyPhongMach.Model;

namespace QuanLyPhongMach.View
{
    /// <summary>
    /// Interaction logic for WThamSo.xaml
    /// </summary>
    public partial class WThamSo : Page
    {
        private CThamSoContext thamsocontext;
        public WThamSo()
        {
            InitializeComponent();
            InitializeFeature();
        }

        #region FUNCTION
        public void Refresh()
        {
        }

        private void InitializeFeature()
        {
            TrangThaiMacDinh();
        }

        private void TrangThaiMacDinh()
        {
            thamsocontext = new CThamSoContext(CConstant.CONNECTION);

            btThayDoi.Visibility = Visibility.Visible;
            btLuu.Visibility = Visibility.Hidden;
            btHuy.Visibility = Visibility.Hidden;
            txtTienKham.IsEnabled = false;
            txtSoBenhNhanToiDaTrongNgay.IsEnabled = false;
            txtSoBenhNhanToiDaTrongNgay.Text = thamsocontext.LayThongTinThamSo().SoLuongKhamToiDaTrongNgay.ToString();
            txtTienKham.Text = thamsocontext.LayThongTinThamSo().TienKham.ToString();
        }

        private void TrangThaiThayDoi()
        {
            txtSoBenhNhanToiDaTrongNgay.IsEnabled = true;
            txtTienKham.IsEnabled = true;
            btThayDoi.Visibility = Visibility.Hidden;
            btLuu.Visibility = Visibility.Visible;
            btHuy.Visibility = Visibility.Visible;
        }

        private void LuuThamSo()
        {

            thamsocontext.CapNhatSoLuongKhamToiDaTrongNgay(Convert.ToInt32(txtSoBenhNhanToiDaTrongNgay.Text));
            thamsocontext.CapNhatTienKham(Convert.ToInt32(txtTienKham.Text));
            MessageBox.Show("Cập Nhật Thành Công");
            TrangThaiMacDinh();
        }

        #endregion

        private void btLuu_Click(object sender, RoutedEventArgs e)
        {
            LuuThamSo();
        }

        private void btHuy_Click(object sender, RoutedEventArgs e)
        {
            TrangThaiMacDinh();
        }

        private void btThayDoi_Click(object sender, RoutedEventArgs e)
        {
            TrangThaiThayDoi();
        }
    }
}
